package online.xybh.qa.controller;

import com.github.pagehelper.PageInfo;
import online.xybh.qa.anno.TeacherLogin;
import online.xybh.qa.dto.TeacherAndClassDTO;
import online.xybh.qa.model.CommonQuestion;
import online.xybh.qa.service.CommonQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author: xybh
 * @Description:
 * @Date: Created in 23:48 2020/10/23
 * @Modified:
 */
@Controller
public class FAQController {

    @Autowired
    private CommonQuestionService commonQuestionService;

    @GetMapping("FAQ")
    @TeacherLogin
    public String index(HttpSession session,
                        Model model,
                        @RequestParam(value = "page",defaultValue = "1") Integer page,
                        @RequestParam(value = "size", defaultValue = "10") Integer size){
        TeacherAndClassDTO user = (TeacherAndClassDTO)session.getAttribute("user");
        model.addAttribute("user", user);
        model.addAttribute("backUrl", "FAQ");
        PageInfo<CommonQuestion> questionList = commonQuestionService.queryAllCommonQuestion(page,size);
        model.addAttribute("questionList", questionList);
        return "common_question";
    }
}
